package com.macroye.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.macroye.entity.Broker;
import com.macroye.entity.req.BrokerLoginVo;
import com.macroye.utils.JwtUtils;
import org.springframework.data.redis.core.RedisTemplate;

import javax.servlet.http.HttpServletRequest;

/**
 * 公共信息处理类
 */
public class InformationCommonImpl {

    /**
     * 查找用户信息
     * @return
     */
    public static BrokerLoginVo findVBroker(RedisTemplate<String,Object> redisTemplate, HttpServletRequest request){
        //获取token
        String token = request.getHeader(JwtUtils.TOKEN);
        // 解析token
        String userKey = JwtUtils.getUserKey(token);
        //获取数据
        String s = String.valueOf(redisTemplate.opsForValue().get(JwtUtils.LOGIN_TOKEN_KEY + userKey));
        // 反序列化

        BrokerLoginVo brokerLoginVo = JSONObject.parseObject(s, BrokerLoginVo.class);
        return brokerLoginVo;
    }

}
